import { EventEmitter } from 'events';
const Events = new EventEmitter();

// loading
function ld(title: string) {
    Events.emit("loading", true, title)
}
function cld() {
    Events.emit("loading", false)
}
// toast
function toast(text: string | { message?: string; callback?: () => void }) {
    Events.emit("toast", text)
}

function dialog(text: string) {
    Events.emit("dialog", text)
}
// 弹框
function box(options: any) {
    Events.emit("modal", options)
}

// 弹框
function openPicker(options: any) {
    Events.emit("openPicker", options)
}

// loading
function lweikaifang() {
    Events.emit("weikaifang", true)
}

function cweikaifang() {
    Events.emit("weikaifang", false)
}

function updateApp(text: string) {
    Events.emit("updateApp", text)
}

(global as any).$ld = ld;
(global as any).$cld = cld;
(global as any).$toast = toast;
(global as any).$box = box;
(global as any).$dialog = dialog;
(global as any).$updateApp = updateApp;
(global as any).$lweikaifang = lweikaifang;
(global as any).$cweikaifang = cweikaifang;
(global as any).$openPicker = openPicker;

export default Events;